package com.socialuni.sdk.manage;

import com.socialuni.sdk.model.DO.user.UserFollowDetailDO;
import com.socialuni.sdk.repository.UserFollowDetailRepository;
import com.socialuni.sdk.model.DO.user.UserDO;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserFollowDetailManage {
    @Resource
    UserFollowDetailRepository userFollowDetailRepository;

    public UserFollowDetailDO createUserDetailFollow(UserDO mineUser) {
        UserFollowDetailDO userFollowDetailDO = new UserFollowDetailDO(mineUser);
        userFollowDetailDO = userFollowDetailRepository.save(userFollowDetailDO);
        return userFollowDetailDO;
    }

    @Async
    public void mineFollowNumAdd(Integer mineUserId) {
        UserFollowDetailDO mineUserFollow = userFollowDetailRepository.findByUserId(mineUserId);
        mineUserFollow.setFollowNum(mineUserFollow.getFollowNum() + 1);
        userFollowDetailRepository.save(mineUserFollow);
    }
    @Async
    public void userFansNumAdd(Integer userId) {
        UserFollowDetailDO userFollow = userFollowDetailRepository.findByUserId(userId);
        userFollow.setFansNum(userFollow.getFansNum() + 1);
        userFollowDetailRepository.save(userFollow);
    }
    @Async
    public void mineFollowNumSub(Integer mineUserId) {
        UserFollowDetailDO mineUserFollow = userFollowDetailRepository.findByUserId(mineUserId);
        mineUserFollow.setFollowNum(mineUserFollow.getFollowNum() - 1);
        userFollowDetailRepository.save(mineUserFollow);
    }
    @Async
    public void userFansNumSub(Integer userId) {
        UserFollowDetailDO userFollow = userFollowDetailRepository.findByUserId(userId);
        userFollow.setFansNum(userFollow.getFansNum() - 1);
        userFollowDetailRepository.save(userFollow);
    }
}
